package com.mayflygeek.mayflyask.framework.webmvc.event;

import java.util.Map;

/**
 * @author 虫虫
 * @team 蜉蝣极客
 * @link www.mayflygeek.com
 * @Emial chongchong@mayflygeek.com
 * 
 */
public final class Events {
	private Events() {

	}

	public static boolean isEvent(Object event) {
		return isEvent(event, Event.class);
	}

	public static boolean isEvent(Object event, Class<? extends Event> eventType) {
		if (event == null || eventType == null) {
			return false;
		}

		if (eventType.isInstance(event)) {
			return true;
		}

		return false;
	}

	public static AfterCreate afterCreateEvent(Object source, Map<String, Object> model) {
		return new AfterCreate(source, model);
	}

	public static AfterCreate afterCreateEvent(Object source) {
		return new AfterCreate(source, null);
	}

	public static AfterUpdate afterUpdateEvent(Object source, Map<String, Object> model) {
		return new AfterUpdate(source, model);
	}

	public static AfterUpdate afterUpdateEvent(Object source) {
		return new AfterUpdate(source, null);
	}

	public static AfterDelete afterDeleteEvent(Object source, Map<String, Object> model) {
		return new AfterDelete(source, model);
	}

	public static AfterDelete afterDeleteEvent(Object source) {
		return new AfterDelete(source, null);
	}

	/**
	 * 已完成创建实体事件
	 * 
	 * @author 虫虫
	 * @team 蜉蝣极客
	 * @link www.mayflygeek.com
	 * @Emial chongchong@mayflygeek.com
	 *
	 */
	public static class AfterCreate extends WebEvent {
		private static final long serialVersionUID = -5839413733645328632L;

		public AfterCreate(Object source, Map<String, Object> model) {
			super(source, model);
		}
	}

	/**
	 * 已完成更新实体事件
	 * 
	 * @author 虫虫
	 * @team 蜉蝣极客
	 * @link www.mayflygeek.com
	 * @Emial chongchong@mayflygeek.com
	 *
	 */
	public static class AfterUpdate extends WebEvent {
		private static final long serialVersionUID = 3730216261692029574L;

		public AfterUpdate(Object source, Map<String, Object> model) {
			super(source, model);
		}
	}

	/**
	 * 已完成删除实体事件
	 * 
	 * @author 虫虫
	 * @team 蜉蝣极客
	 * @link www.mayflygeek.com
	 * @Emial chongchong@mayflygeek.com
	 *
	 */
	public static class AfterDelete extends WebEvent {
		private static final long serialVersionUID = 8928675036949067338L;

		public AfterDelete(Object source, Map<String, Object> model) {
			super(source, model);
		}
	}
}
